/**
 * 
 */
package x.java.util.zip;

import java.io.File;
import java.io.IOException;
import java.util.zip.ZipException;

/**
 * @author qiangli
 * 
 */
public class ZipFile extends java.util.zip.ZipFile {
	private x.java.io.File file = null;
	
	private int mode = OPEN_READ;
	
	/**
	 * @param name
	 * @throws IOException
	 */
	public ZipFile(String name) throws IOException {
		this(new x.java.io.File(name), OPEN_READ);
	}

	/**
	 * @param file
	 * @throws ZipException
	 * @throws IOException
	 */
	public ZipFile(File file) throws ZipException, IOException {
		this((x.java.io.File)file, OPEN_READ);
	}

	/**
	 * @param file
	 * @param mode
	 * @throws IOException
	 */
	public ZipFile(File file, int mode) throws IOException {
		this((x.java.io.File)file, mode);
	}

	private ZipFile(x.java.io.File file, int mode) throws IOException {
		super(replicate(file), mode(file));
		this.file = file;
		this.mode = mode;
	}

	
	private static File replicate(x.java.io.File file) {
		try {
			return file.getNativeFile();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return null;
	}

	public void close() throws IOException {
		super.close();
		if (mode == OPEN_DELETE) {
			file.delete();
		}
	}

	public String getName() {
		return file.getPath();
	}
	
	private static int mode(x.java.io.File file) {
		return file.isNative() ? OPEN_READ : OPEN_DELETE;
	}
}
